﻿using System;
using System.Collections;
using BLL;

namespace MakeBabyWebApplication
{
    public partial class register : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //只响应POST请求
            if (Request.HttpMethod == "POST")
            {
                string email = Request.Params["email"];
                string password = Request.Params["password"];
                string name = Request.Params["name"];
                string sex = Request.Params["sex"];
                //Response.Write("<script>alert('" + email + password + name + sex +".."+ "')</script>");
                //服务端非空检测
                if (email == "")
                {
                    Response.Write("<script>alert('email为空...')</script>");
                    return;
                }
                else if (password == "")
                {
                    Response.Write("<script>alert('password为空...')</script>");
                    return;
                }
                else if (name == "")
                {
                    Response.Write("<script>alert('name为空...')</script>");
                    return;
                }
                else
                {
                    //开始存入数据库
                    UserService userService = new UserService();
                    Hashtable ht = userService.regist(email, password, name, sex);
                    string result = (string)ht["result"];
                    string message = (string)ht["message"];

                    if (result == "1")
                    {
                        Response.Redirect("login.aspx");
                    }
                    else
                    {
                        Response.Write("<script>alert('" + "注册失败--" + message + "')</script>");
                    }
                }
            }
        }
    }
}